package logic;

import data.Account;
import data.DbConnection;

/**
 * Class InterestAccuruel and its instance variables
 * 
 * @author Niels - niha12ai
 * 
 *         The class contains the InterestAccruel method which adds interest to
 *         every users accounts depending on which konto type
 */
public class InterestAccruel {

	private DbConnection dbConnection;

	/**
	 * the interest method
	 */
	public void interestAccruel() {
		dbConnection = new DbConnection();
		/**
		 * runs through accounts and adds interest according to the konto type
		 */
		for (Account account : dbConnection.getAccounts()) {
			if (account.getKontoType().equals("Savings")) {
				dbConnection.updateAccountSaldo(
						account.getTotalBalance() * 1.05,
						account.getAccountNumber());

				double balance = account.getTotalBalance();
				double balanceWithInterest = account.getTotalBalance() * 1.05;
				double difference = balanceWithInterest - balance;
				dbConnection.updateAvailableBalanceSaldo(
						account.getAvailableBalance() + difference,
						account.getAccountNumber());

			}

			else if (account.getKontoType().equals("Salary Account"))
				dbConnection.updateAccountSaldo(
						(account.getTotalBalance() * 1.01),
						account.getAccountNumber());

			double balance = account.getTotalBalance();
			double balanceWithInterest = account.getTotalBalance() * 1.01;
			double difference = balanceWithInterest - balance;
			dbConnection.updateAvailableBalanceSaldo(
					account.getAvailableBalance() + difference,
					account.getAccountNumber());

		}

	}
}
